﻿using Microsoft.AspNetCore.SignalR.Client;
using System.Collections.Generic;

namespace JNPF.Utils
{
    /// <summary>
    /// SignalR推送
    /// 版 本：V3.0.0
    /// 版 权：引迈信息技术有限公司（https://www.jnpfsoft.com）
    /// 作 者：JNPF开发平台组
    /// </summary>
    public class MessagePushHelper
    {
        /// <summary>
        /// 静态实例
        /// </summary>
        public static MessagePushHelper Instance
        {
            get { return new MessagePushHelper(); }
        }
        HubConnection hubConnection { get; set; }
        public MessagePushHelper()
        {
            var url = ConfigurationKey.SignalRUrl;
            hubConnection = new HubConnectionBuilder().WithUrl(url).Build();
            hubConnection.StartAsync();
        }
        /// <summary>
        /// 发送通知
        /// </summary>
        /// <param name="tenantId">tenantId</param>
        /// <param name="toUserIds">发送用户</param>
        /// <param name="messageContent">消息信息</param>
        /// <param name="messageType">消息分类：1-系统公告，2-系统消息</param>
        public void SendNotice(string tenantId, List<string> toUserIds, string messageContent, string messageType)
        {
            hubConnection.InvokeAsync("pushNotice", tenantId, toUserIds, messageContent, messageType);
            hubConnection.StopAsync();
        }

    }
}
